<template>
	<view>
		<view class="search">
		<search-bar @click="goSearch"></search-bar>
		</view>
		<!-- 轮播图 -->
		<swiper circular :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in swiperList" :key="index" >
			<navigator :url="`/subpkg/goods-detail/goods-detail?goods_id=${item.goods_id}`">
				<image class="swiper-img" :src="item.image_src"></image>
			</navigator>
			</swiper-item>
		</swiper>
		<!-- 导航栏 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" :key="index">
				<image :src="item.image_src" @click="goCate(index)"></image>
			</view>
		</view>
		<!-- 楼层 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<!-- 标题 -->
				<view class="floor-title">
					<image :src="item.floor_title.image_src"></image>
				</view>
				<!-- 内容 -->
				<view class="floor-content">
					<!-- 左 -->
					<view class="left">
						<image @click="goList(item.product_list[0])" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}" :src="item.product_list[0].image_src"></image>
					</view>
					<!-- 右 -->
					<view class="right">
						<image @click="goList(e)" mode="widthFix" :style="{width:e.image_width+'rpx'}" :key="i" v-for="(e,i) in item.product_list" v-if="i !== 0" :src="e.image_src"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tabBarMixins from '../../mixins/tabBarMixins.js'
	export default {
		data() {
			return {
				// 轮播图数据
				swiperList:[],
				// 导航栏数据
				navList:[],
				// 楼层
				floorList:[]
			};
		},
		mixins:[tabBarMixins],
		onLoad(){
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods:{
			// 跳转到搜索
			goSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			},
			// 跳转到商品列表
			goList(obj){
				// console.log(obj.navigator_url.split('?')[1])
				const param = obj.navigator_url.split('?')[1]
				uni.navigateTo({
					url:`/subpkg/goods-list/goods-list?${param}`
				})
			},
			// 楼层
			async getFloorList(){
				const {data:{message,meta}} = await uni.$http.get('/api/public/v1/home/floordata')
				// console.log(message)
				// 判断是否获取成功
				if(meta.status !==200){
					return uni.$showMsg()
				}
				this.floorList=message
			},
			// 跳转到分类函数
			goCate(index){
				if(index===0){
					// console.log('1')
					// 跳转
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			// 导航栏
			async getNavList(){
				const {data:{message,meta}} = await uni.$http.get('/api/public/v1/home/catitems')
				// console.log(res)
				// 判断是否获取成功
				if(meta.status !==200){
					return uni.$showMsg()
				}
				this.navList=message
			},
			// 轮播图
			async getSwiperList(){
				const {data:{message,meta}} = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(res)
				// 判断是否获取成功
				if(meta.status !==200){
					return uni.$showMsg()
				}
				this.swiperList=message
			}
			
			
		}
	}
</script>

<style lang="scss">
.search{
	position: sticky;
	left: 0;
	top: 0;
	right: 0;
	z-index: 999;
	
}
.swiper-img{
	width: 100%;
	height: 330rpx;
}
.nav-list{
	display: flex;
	justify-content: space-around;
	margin: 6px 0;
	.nav-item{
		width: 128rpx;
		height: 140rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
}
.floor-title{
	image{
		width: 100%;
		height: 59rpx;
	}
}
.floor-content{
	display: flex;
	padding: 6px;
	.right{
		margin-left: 6px;
		display: flex;
		justify-content: space-around;
		flex-wrap: wrap;
	}
}
</style>
